/* $Id: Round.java 39 2009-07-24 22:48:06Z h_m_r@gmx.de $ */
package org.jugger.tournament.model;

import java.util.ArrayList;

/**
 * @author Sven Hamer
 */
public class Round extends ArrayList<Match> {

	private static final long serialVersionUID = 5070208969187698747L;

	@Override
	public String toString() {
		String matches = "Round:";
		for(Match match: this) {
			matches += (matches.equals("") ? "    " : "\n    ") + match;
		}
		return matches;
	}

	public boolean isReadyForNextRound() {
		for(Match match: this) {
			if(!match.isFinished())
				return false;
		}
		return true;
	}

	public boolean isFinishable() {
		for(Match match: this) {
			if(!match.isFinishable())
				return false;
		}
		return true;
	}

	/**
	 * If there are at least two matches, that are not started yet (0:0), then a round is recalculatable.
	 * @return
	 */
	public boolean isRecalculatable() {
		int notStarted = 0;
		for(Match match: this) {
			if(match.isRecalculatable())
				if(++notStarted == 2)
					return true;
		}
		return false;
	}
}
